/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ctrl;

import com.cxhd.lis.model.newmodel.ZkControlmaterials;
import static com.cxhd.lis.model.newmodel.ZkControlmaterials.zkControlmaterialsdao;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;


/**
 *
 * @author cxhd
 */
@ControllerBind(controllerKey ="view/lis/zkcontrol")
public class ZkControlmaterialsCtrl extends Controller{
     public void index(){
        render("/view/lis/zk_controlmaterials.jsp");
    }
      public void getZkControls(){
          String sql="select PK,MAJORPK,PRODUCTIONTIME, BATCHNUMBER,EXFACTORY,EFFECTIVETIME,(select MAJORNAME  from zk_major m where m.PK=c.MAJORPK) MAJORNAME1 ";
          String param=" from zk_controlmaterials c where BATCHNUMBER like '%"+getPara("searchContent")+"%' or EXFACTORY like '%"+getPara("searchContent")+"%'";
       Page<Record> userPage =Db.use("mysql").paginate(getParaToInt("currentPage",getParaToInt("currentPage")), getParaToInt("pageSize",getParaToInt("pageSize")), sql, param);
       renderJson(userPage);
     }
     public void getZkControlsRep(){ 
           List<Record> list= Db.use("mysql").find("select * from zk_controlmaterials where BATCHNUMBER=?",getPara("REAGENTNUMBER"));
       if(list.size()!=0){ 
            if(getPara("PK")!=""&&getPara("PK")!=null){//判断是新增还是修改
                if(Integer.valueOf(getPara("PK"))==list.get(0).get("PK")){ //修改是允许修改（本身主键和查询到的主键相同）
                     renderText("false");
                }else{
                   renderText("true");  
                }
            }else{
                renderText("true");
            }
        
        }else{
            renderText("false");
        }
     }
     public void deleteZkControl(){
         try{
             new ZkControlmaterials().deleteZkControl(getPara("PK"));
         }catch( Exception e){
            renderJson("false");
         }
         renderJson("true");
         
     }
     public void saveZkControl(){
           new ZkControlmaterials().saveZkControl(this);
         renderText("true");
     }
     public void updateZkControl(){
        zkControlmaterialsdao.updateZkControl(this);
        renderText("true");
     }
     //MAJORPK
     public void getMajors(){//获取专业组信息
        renderJson(Db.use("mysql").find("select * from zk_major"));
     }
}
